import Ability from '@ohos.application.Ability'
import Window from '@ohos.window'

export default class MainAbility extends Ability {
  onCreate(want, launchParam) {
    console.info('MainAbility onCreate')
    globalThis.abilityContext = this.context
  }

  onDestroy() {
    console.info('MainAbility onDestroy')
  }

  onWindowStageCreate(windowStage: Window.WindowStage) {
    console.info('MainAbility onWindowStageCreate')
    
    windowStage.loadContent('pages/Index', (err, data) => {
      if (err.code) {
        console.error('Failed to load the content. Cause: ' + JSON.stringify(err))
        return
      }
      console.info('Succeeded in loading the content. Data: ' + JSON.stringify(data))
    })
  }

  onWindowStageDestroy() {
    console.info('MainAbility onWindowStageDestroy')
  }

  onForeground() {
    console.info('MainAbility onForeground')
  }

  onBackground() {
    console.info('MainAbility onBackground')
  }
}